package com.ll.studentservice.controller;


import com.ll.commonUtils.R;
import com.ll.studentservice.entity.EduClassroom;
import com.ll.studentservice.service.EduClassroomService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 课室表 前端控制器
 * </p>
 *
 * @author ll
 * @since 2020-11-26
 */
@Api(description = "课室信息增删改查API") //swagger界面提示
@RestController
@RequestMapping("/studentservice/educlassroom")
public class EduClassroomController {

    @Autowired
    private EduClassroomService eduClassroomService;

    @GetMapping("findAllClassroom")
    @ApiOperation(value = "获取所有课室的信息") //swagger界面提示
    public R findAllClassroom(){
        List<EduClassroom> eduClassrooms = eduClassroomService.list(null);

        return R.ok().data("allClassroomInfo", eduClassrooms);
    }

    @GetMapping("findOneClassroom/{classroomId}")
    @ApiOperation(value = "获取单个课室的信息") //swagger界面提示
    public R findOneClassroom(@PathVariable String classroomId){
        EduClassroom eduClassroom = eduClassroomService.getById(classroomId);
        if (StringUtils.isEmpty(eduClassroom)){
            return R.error().message("没有这个课室的信息");
        } else {
            return R.ok().data("classroomInfo", eduClassroom);
        }
    }

    @PostMapping("addOneClassroom")
    @ApiOperation(value = "添加课室") //swagger界面提示
    public R addOneClassroom(@RequestBody EduClassroom eduClassroom){
        // 添加单个课室
        boolean save = eduClassroomService.save(eduClassroom);
        return save ? R.ok().message("添加课室信息成功") : R.error().message("添加课室信息失败");
    }

    @DeleteMapping("deleteClassroom/{classroomId}")
    @ApiOperation(value = "删除课室信息") //swagger界面提示
    public R deleteClassroom(@PathVariable String classroomId){
        boolean b = eduClassroomService.removeById(classroomId);
        return b ? R.ok().message("删除课室信息成功") : R.error().message("删除课室信息失败");
    }

    @PostMapping("updateClassroom")
    @ApiOperation(value = "修改课室信息") //swagger界面提示
    public R updateClassroom(@RequestBody EduClassroom eduClassroom){
        boolean b = eduClassroomService.updateById(eduClassroom);
        return b ? R.ok().message("修改课室信息成功") : R.error().message("修改课室信息失败");
    }





}

